package com.liugui.iostream;

import java.io.*;

/**
 * @ClassName: Test
 * @Author: liugui
 * @Date: 2020-11-05 15:39
 **/
public class Test {
    public static void main(String[] args) {
        //作为输入流的数据文件必须存在 否则抛出异常
        File file = new File("E:\\home\\project\\file1.txt");
        //file2.txt没有，系统可以创建
        File outFile = new File("file2.txt");
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(outFile);
            int c;
            while((c = fis.read()) != -1){
                fos.write(c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch(IOException e){
            System.err.println("FileStreamTest:" + e);
        }finally {
            //打开了文件一定要记着关，释放系统资源
            try {
                fis.close();
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



    }
}
